package com.pengshun.modules.api.transport.controller;

import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Fourth;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.transport.dto.CarNumberDto;
import com.pengshun.modules.api.transport.dto.FreightSettlementDto;
import com.pengshun.modules.api.transport.dto.TransportDto;
import com.pengshun.modules.api.transport.dto.TransportTakeCarriageDto;
import com.pengshun.modules.api.transport.service.TakeTransportOrderService;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "接单管理")
@RequestMapping("/api/take")
public class TakeTransportOrderController {


    private final TakeTransportOrderService takeTransportOrderService;

    @ApiOperation(value = "车主接单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态 0全部 1进行中，2已完成", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/car-list")
    @Authorization
    public BaseResult carList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = takeTransportOrderService.list(para);
        return res;
    }
    @ApiOperation(value = "车主/运输公司 车辆接单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态 0全部 1进行中，2已完成", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/owner-list")
    @Authorization
    public BaseResult ownerList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = takeTransportOrderService.ownerList(para);
        return res;
    }
    @ApiOperation(value = "车辆接单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TransportTakeCarriageId", value = "id", dataType = "int", paramType = "query"),
    })
    @GetMapping(value = "/owner-detil")
    public BaseResult ownerDetil(@ApiIgnore @Validated(value = {Second.class}) TransportTakeCarriageDto para) throws Exception {
        BaseResult res = takeTransportOrderService.ownerDetil(para.getTransportTakeCarriageId());
        return res;
    }

    @ApiOperation(value = "司机接单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态 0全部 1待装货、2已装货、3卸货", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportTakeOrderId", value = "车主查看分配列表传", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/driver-list")
    @Authorization
    public BaseResult driverList(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = takeTransportOrderService.driverList(para);
        return res;
    }

    @ApiOperation(value = "车主/运输公司接单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportTakeOrderId", value = "id", dataType = "int", paramType = "query"),
    })
    @GetMapping(value = "/detil")
    public BaseResult detil(@ApiIgnore @Validated(value = {First.class}) TransportTakeCarriageDto para) throws Exception {
        BaseResult res = takeTransportOrderService.detil(para.getTransportTakeOrderId());
        return res;
    }
    @ApiOperation(value = "司机接单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TransportTakeCarriageId", value = "id", dataType = "int", paramType = "query"),
    })
    @GetMapping(value = "/driver-detil")
    public BaseResult driverDetil(@ApiIgnore @Validated(value = {Second.class}) TransportTakeCarriageDto para) throws Exception {
        BaseResult res = takeTransportOrderService.driverDetil(para.getTransportTakeCarriageId());
        return res;
    }
    @ApiOperation(value = "司机取消接单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TransportTakeCarriageId", value = "id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/cancle")
    @Authorization
    public BaseResult cancle(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Second.class}) TransportTakeCarriageDto para) throws Exception {
        BaseResult res = takeTransportOrderService.cancle(user.getId(),para.getTransportTakeCarriageId());
        return res;
    }
    @ApiOperation(value = "司机删除接单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TransportTakeCarriageId", value = "id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/del")
    @Authorization
    public BaseResult del(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Second.class}) TransportTakeCarriageDto para) throws Exception {
        BaseResult res = takeTransportOrderService.del(user.getId(),para.getTransportTakeCarriageId());
        return res;
    }

    @ApiOperation(value = "接单操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportTakeCarriageId", value = "id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态 2装货、3卸货", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/update")
    @Authorization
    public BaseResult update(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) FreightSettlementDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = takeTransportOrderService.update(para);
        return res;
    }

    @ApiOperation(value = "分配列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportTakeOrderId", value = "id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "1:待分配2 已分配", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @GetMapping(value = "/allot")
    @Authorization
    public BaseResult findAllotList(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {First.class}) TransportTakeCarriageDto para) throws Exception {
        BaseResult res = takeTransportOrderService.findAllotList(user.getId(),para.getTransportTakeOrderId(),para.getStatus());
        return res;
    }
    @ApiOperation(value = "分配保存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportTakeOrderId", value = "id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "carNumber", value = "接单车牌号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "carOwnerId", value = "接单车辆ID", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "carPhoto", value = "车辆照片", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "carLoad", value = "载重", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "typeName", value = "车辆类型", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "运输用户id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "运输人姓名", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "number", value = "数量", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/allot-save")
    @Authorization
    public BaseResult allotSave(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {First.class}) CarNumberDto para) throws Exception {
        para.setAllotUserId(user.getId());
        BaseResult res = takeTransportOrderService.allotSave(para);
        return res;
    }
    @ApiOperation(value = "分配修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportTakeCarriageId", value = "分配id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "transportTakeOrderId", value = "分配id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "userId", value = "运输用户id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "name", value = "运输人姓名", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "number", value = "数量", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/allot-update")
    @Authorization
    public BaseResult allotUpdate(@ApiIgnore @CurrUserInfo User user,@ApiIgnore @Validated(value = {Fourth.class}) CarNumberDto para) throws Exception {
        para.setAllotUserId(user.getId());
        BaseResult res = takeTransportOrderService.allotUpdate(para);
        return res;
    }

}
